import { getFabAreaSelectOptions, queryFabPlanNoList, queryFabJobNoList, queryFabJobStatusList } from "@/api/modules/fab";

/**
 * @description: 获取search配置信息
 * @return {Array<CommonSearch.SearchOption>}
 */
export const useSearchOption = (flag: boolean = false): Array<CommonSearch.SearchOption> => {
  const eqpId: CommonSearch.SearchOption = {
    label: "机台编号",
    key: "eqpId",
    value: "",
    type: "input",
    placeholder: "请输入机台编号"
  };

  const areaId: CommonSearch.SearchOption = {
    label: "区域",
    key: "areaId",
    value: null,
    type: "select",
    axiosApi: getFabAreaSelectOptions,
    // mapOption: ({ areaId: value = "", areaCode: label = "" }: any) => ({ value, label }),
    formatOption: (res: Array<any>): Array<any> => {
      return res?.map(({ areaId: value = "", areaCode: label = "" }: any) => ({ value, label }))?.filter(({ value, label }) => !!value && !!label);
    },
    placeholder: "请选择区域"
  };

  const category: CommonSearch.SearchOption = {
    label: "类型",
    key: "category",
    value: null,
    type: "select",
    typeCode: "FAB_PM_CATEGORY",
    placeholder: "请选择类型"
  };

  const planNo: CommonSearch.SearchOption = {
    label: "计划编号",
    key: "planNo",
    value: "",
    type: "select",
    remote: true,
    selectRemoteApi: queryFabPlanNoList,
    getParams: (planNo: string) => ({ planNo }),
    mapOption: ({ code: value = "", name: label = "" }: any) => ({ value, label }),
    placeholder: "请选择计划编号"
  };

  const jobNo: CommonSearch.SearchOption = {
    label: "任务编号",
    key: "jobNo",
    value: "",
    type: "select",
    remote: true,
    selectRemoteApi: queryFabJobNoList,
    getParams: (jobNo: string) => ({ jobNo }),
    mapOption: ({ code: value = "", name: label = "" }: any) => ({ value, label }),
    placeholder: "请选择任务编号"
  };

  const jobStatus: CommonSearch.SearchOption = {
    label: "任务状态",
    key: "jobStatus",
    value: null,
    type: "select",
    axiosApi: queryFabJobStatusList,
    mapOption: ({ code: value = "", name: label = "" }: any) => ({ value, label }),
    placeholder: "请选择任务状态"
  };

  const pmTimeStart: CommonSearch.SearchOption = {
    label: "维保时间",
    key: "pmTimeStart",
    realKeys: ["pmTimeStart", "pmTimeEnd"],
    value: [],
    type: "daterange",
    span: 6
  };
  if (flag) {
    return [pmTimeStart, eqpId, areaId, jobNo, planNo, jobStatus];
  } else {
    return [pmTimeStart, eqpId, areaId, category, jobNo, planNo, jobStatus];
  }
};

/**
 * @description:  获取table表格的表头（cloumns）信息
 * @return {Array<CommonTable.TableCloumnsType>}
 */
export const useTableCloumns = (flag: boolean = false, cb?: (scope: any) => void): Array<CommonTable.TableCloumnsType> => {
  const tagMapOption = new Map([
    [
      "completed",
      {
        color: "#28D892",
        label: "Completed"
      }
    ],
    [
      "ongoing",
      {
        color: "#F59E0B",
        label: "Ongoing"
      }
    ],
    [
      "created",
      {
        color: "#3B82F6",
        label: "Created"
      }
    ]
  ]);

  // const tagMapOption2 = new Map([
  //   [
  //     "unScheduling",
  //     {
  //       color: "#10B981",
  //       label: "UnScheduling"
  //     }
  //   ],
  //   [
  //     "condition",
  //     {
  //       color: "#3B82F6",
  //       label: "Condition"
  //     }
  //   ],
  //   [
  //     "scheduling",
  //     {
  //       color: "#F59E0B",
  //       label: "Scheduling"
  //     }
  //   ],
  //   [
  //     "times",
  //     {
  //       color: "#CBA1FE",
  //       label: "Times"
  //     }
  //   ]
  // ]);

  const o_1 = {
    label: "机台编号",
    prop: "eqpId",
    cloumnClick: (scope: any) => {
      cb && cb(scope);
    }
  };
  const o_2 = {
    label: "区域",
    prop: "areaId"
  };

  const o_3 = {
    label: "类型",
    prop: "category"
    // tagMapOption: tagMapOption2,
    // tagType: "point",
    // defaultTagValue: "condition",
    // mapRow: ({ row: { category: value = "" } }: any) => ({ value })
  };

  // const o_4 = {
  //   label: "任务编号",
  //   prop: "jobNo",
  //   sortable: "custom"
  // };
  // const o_5 = {
  //   label: "计划编号",
  //   prop: "planNo",
  //   sortable: "custom"
  // };
  const o_6 = {
    label: "任务标题",
    prop: "title"
  };
  const o_6_1 = {
    label: "触发维保周期",
    prop: "triggerSeason"
  };

  const o_7 = {
    label: "触发代码",
    prop: "triggerCode"
  };

  const o_7_1 = {
    label: "Activity",
    prop: "activityCode"
  };

  const o_8 = {
    label: "任务状态",
    prop: "jobStatus",
    tagMapOption,
    tagType: "point",
    defaultTagValue: "processing",
    mapRow: ({ row: { jobStatus: value = "" } }: any) => ({ value })
  };

  const o_8_1 = {
    label: "操作人",
    prop: "operator"
  };

  const o_9 = {
    label: "最早开始时间",
    prop: "earlyDate",
    sortable: "custom"
  };

  const o_9_1 = {
    label: "Activity Times",
    prop: "activityDate"
  };

  const o_10 = {
    label: "计划执行时间",
    prop: "dueDate",
    sortable: "custom"
  };

  const o_10_1 = {
    label: "实际维保耗时",
    prop: "actPmHours",
    sortable: "custom"
  };

  const o_11 = {
    label: "最晚结束时间",
    prop: "lateDate",
    sortable: "custom"
  };
  if (flag) {
    return [o_1, o_2, o_3, o_6_1, o_7_1, o_8_1, o_9_1, o_10_1];
  } else {
    return [o_1, o_2, o_3, o_6, o_7, o_8, o_9, o_10, o_11];
  }
};
